﻿using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Net.Http;
using CNI.Models;
using System.Net.Http.Formatting;

namespace CNI.Tests
{
    [TestClass]
    public class IngestTest
    {
        private HttpClient httpClient;

        [TestInitialize]
        public void Initialize()
        {
            httpClient = new HttpClient();
            httpClient.BaseAddress = new Uri("http://127.0.0.1:80/api/device");
        }

        [TestMethod]
        public void PostDeviceData()
        {
            var data = new DeviceData()
            {
                HardwareId = Guid.NewGuid().ToString(),
                Heading = 110.12,
                Latitude = 75.2,
                Longitude = 90.7,
                Speed = 55.4,
                TimeStamp = DateTime.UtcNow
            };

            // Test using JSON
            HttpResponseMessage response = httpClient.PostAsync<DeviceData>
                ("", data, new JsonMediaTypeFormatter()).Result;
            Assert.IsTrue(response.IsSuccessStatusCode);

            // Test using XML
            response = httpClient.PostAsync<DeviceData>
                ("", data, new XmlMediaTypeFormatter()).Result;
            Assert.IsTrue(response.IsSuccessStatusCode);
        }
    }
}
